<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.kma.ncpractice2013.dao.UserDAO" %>
<%@ page import="com.kma.ncpractice2013.model.User" %>
<%@ page import="com.kma.ncpractice2013.dao.UserGroupDAO" %>
<%@ page import="com.kma.ncpractice2013.model.UserGroup" %>
<%@ page import="com.kma.ncpractice2013.model.Commission" %>
<%@ page import="com.kma.ncpractice2013.model.Discount" %>
<%
    int minDiscount = Discount.getMinimalDiscount();
    int maxDiscount = Discount.getMaximalDiscount();
%>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Promo-codes</title>
<link rel="stylesheet" href="promocodes.css" />
<link rel="stylesheet" href="paging.css" />
<link rel="stylesheet" href="https://code.jquery.com/ui/1.10.3/themes/start/jquery-ui.css" />
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script src="https://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script type="text/javascript" src="paging.js"></script>
<script>
	var minDiscount = <%= Discount.getMinimalDiscount() %>;
	var maxDiscount = <%= Discount.getMaximalDiscount() %>;
</script>
<script type="text/javascript" src="promocodes.js"></script>

<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
</head>

<body>

<div id="header-wrapper">
<div id="header" class="container">
	<div id="logo">
    	<h1><a href="#">Accommodation</a></h1>
    </div>
    <%

            String b = (String)session.getAttribute("auth");
			User user = (User)session.getAttribute("user");
            if(b!=null && b.equals("true"))
            {

                out.print("<div id=\"auth\"><form>" +
				"Welcome, <a href='/user/userProfile.jsp'>"+ 
				user.getName() + "</a> | " +
                                  "<a href=\"/logout.jsp\">Log out</a>" +
						  "</form></div>\n");
            }

        else
        out.print("<div id=\"auth\">" +
                                  "<form method=\"post\" action=\"Auth\">"+
                          "        <input size=\"20\" type=\"text\" placeholder=\"e-mail\" name=\"username\">\n" +

                          "        <input size=\"15\" type=\"password\" placeholder=\"password\" name=\"password\">\n" +
                          "        <input type=\"submit\" value=\"Log in\">\n" +
                          "        <a id=\"regist\" href=\"register.jsp\">Register</a>\n" +
                                "</form>"+
						  "        <br clear=\"all\"><a id=\"reset_pass\" href=\"resetPassword.jsp\">Forgot your password?</a>\n" +
                          "    </div>\n");
    %>


</div>
</div>

<div id="menu-wrapper">
<div id="menu" class="container">
<%
	if(b!=null && b.equals("true") && user != null)
	{
		User.AccessLevel accessLevel = user.getAccessLevelId();
		if (accessLevel == User.AccessLevel.administrator)
		{
			out.print("<ul>\n"+
			 "<li class=\"active\"><a href=\"#\">Main page</a></li>\n" + 
			 "<li><a href=\"user/userProfile.jsp\">Profile</a></li>\n" +
			 "<li><a href=\"admin/dashboard.jsp\">Admin's dashboard</a></li>\n" +
				"</ul>\n");
		}
		else if (accessLevel == User.AccessLevel.manager)
		{
			out.print("<ul>\n"+
			 "<li><a href=\"/main_page.jsp\">Main page</a></li>\n" + 
			 "<li><a href=\"/user/userProfile.jsp\">Profile</a></li>\n" +
			 "<li><a href=\"/manager/discounts.jsp\">Comissions and discounts</a></li>\n" +
			 "<li class=\"active\"><a href=\"/manager/promocodes.jsp\">Promo-codes</a></li>\n" +
			 "<li><a href=\"/manager/vipstatus.jsp\">VIP-status</a></li>\n" +
			 "<li><a href=\"/manager/reports.jsp\">Reports</a></li>\n" +
				"</ul>\n");
		}
	}
%>
</div>
</div>

<div id="content-wrapper">
<div id="content" class="container">

    <div id="search-part">
        <header>Create promotional codes</header>
        <ul>
            <li>Current promotional code discount: <span type="text" id="discount">7</span>%</li>
            <li>
                <%= minDiscount %>%
                <div id='slider' class='slider'></div>
                <%= maxDiscount %>%
            </li>
            <li>
            	<div id="check-in">From: <input type="text" id="startDate" size="15" readonly/></div>
        		<div id="check-out">To: <input type="text" id="endDate" size="15" readonly/></div>
            </li>
            <li>Number of codes: <input type="number" id="number" value="20" onkeypress='validate(event)' min="0" max="1000"/></li>
            <li>
                <input type='button' id='button' value='Generate promo-codes' onclick='generatePromocodes()' >
                &nbsp;&nbsp;<span type="text" id="message" style="font-weight:bold"></span>
            </li>
    	</ul>
    </div>   
    
    <div id="results">
    	<header>Existing promotional codes: <span type="text" id="results-count"></span></header>
        <div class="left-column"><span type="text" class="helper">Sort by:</span> 
            <select id='sortBy'>
                <option value='startingDate' selected='selected'>starting date</option>
                <option value='duration'>duration</option>
            </select>
        </div>
        <div class="right-column">
    		<input type='checkbox' id='showExpired' class="helper">
            <span type="text" class="helper">show expired</span></input>
        </div>
        <br clear="all">
        <table id="result-table">
        </table>
        <div id="pageNavPosition" class="pageNavigation"></div>
    </div>
    
</div>
</div>

<div id="copyright-wrapper">
<div id="copyright" class="container">
<p>Copyright (c) 2013. All rights reserved.</p>
</div>
</div>

</body>

</html>
